package com.kx.springmvc.controller;
import com.kx.springmvc.pojo.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ClassName JsonController
 * @Author Sun
 * @Date 2021/5/20 18:46
 */

@RestController //相当于 @Controller和@RequestBody两个注解
@RequestMapping("/json")
public class JsonController {

    @RequestMapping("/json")
    public User testJson(){
        User user = new User();
        user.setName("孙晋超");
        //密码数据不能返回，在类中使用 @JsonIgnore设置
        user.setPassword("123456");
        //让空数据不返回，需要在类中设置 @JsonInclude(JsonInclude.Include.NON_EMPTY)
        user.setAddress("");
        user.setAge(18);
        //格式化日期类型  @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
        user.setBirthday(new Date());
        return user;
    }

    @RequestMapping("/date")
    public User testDate(@RequestBody User user) {
        return user;
    }
}
